package com.cskaoyan.controller.promote;

import com.cskaoyan.bean.MallAd;
import com.cskaoyan.model.bo.promote.BasePara;
import com.cskaoyan.model.bo.promote.SimpleMallAd;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.promote_ad.BaseData;
import com.cskaoyan.service.promote.AdvertService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *推广管理/广告管理模块
 * @author：23117
 * @date: 2021/11/30
 */
@RestController
@RequestMapping("admin/ad")
public class AdvertController {
    @Autowired
    AdvertService advertService;

    @RequiresPermissions("admin:ad:list")
    @RequestMapping("list")
    public BaseRespVo list(BasePara basePara){
        BaseData data = advertService.list(basePara);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions("admin:ad:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody SimpleMallAd simpleMallAd){
        MallAd vo = advertService.create(simpleMallAd);
        return BaseRespVo.ok(vo);
    }

    @RequiresPermissions("admin:ad:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MallAd mallAd){

        boolean status = advertService.update(mallAd);

        if (status) return BaseRespVo.ok();
        return BaseRespVo.fail("更新失败");
    }

    @RequiresPermissions("admin:ad:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MallAd mallAd){
        boolean status = advertService.delete(mallAd);

        if (status){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败");
    }
}


